layui.use(['jquery', 'form', 'ax'], function () {
    var $ = layui.jquery;
    var form = layui.form;
    var $ax = layui.ax;

    var msg = $("#msg").val();
    //消息提示
    if (msg) {
        system.error(msg);
    }

    //验证码控制
    var ajax = new $ax(system.contextPath + "/base/captchaInterceptInfo/search/captcha/info");
    var param = {
        uri: system.contextPath + "/admin/login"
    }
    ajax.set(param);
    var result = ajax.start();
    if (result.status && result.data.isCheck) {
        var type = result.data.captchaType;
        $('#captcha-' + type + "-container").removeClass('hide').show();
        $('#captcha-' + type).attr('lay-verify', "required")

        var $showContainer = $('#captcha-' + type + "-show-container").removeClass('hide').show();
        var width = $showContainer.data("width");
        var height = $showContainer.data("height");
        captcha.init($showContainer, type, system.contextPath + "/captcha/" + type + "/get", {
            width: width
            , height: height
        }, width, height);
    }

    //登录
    form.on('submit(login)', function (data) {
        // var username = $('#username').val();
        // var password = md5($('#password').val());
        // // var param = {
        // //     data: encodeURIComponent(JSON.stringify({"username": username, "password": password}))
        // // }
        //
        // var param = {
        //     data: encodeURIComponent(JSON.stringify({"username": username, "password": password}))
        // }
        // var ajax = new $ax(system.contextPath + "/admin/login");
        // ajax.set(param);
        // var result = ajax.start();
        // if (result.code === "0") {
        //     location.href = system.contextPath + "/admin/index";
        // }
        return true;
    });
    form.verify({
        username: function (value, item) {
            if (!new RegExp("^[a-zA-Z0-9_\u4e00-\u9fa5\\s·]+$").test(value)) {
                return '用户名不能有特殊字符';
            }
            if (/(^\_)|(\__)|(\_+$)/.test(value)) {
                return '用户名首尾不能出现下划线\'_\'';
            }
            if (/^\d+\d+\d$/.test(value)) {
                return '用户名不能全为数字';
            }
            if (!/^[\S]{5,20}$/.test(value)) {
                return '用户名只能在6到20个字符之间';
            }
        },
        password: [/^[\S]{5,12}$/, '密码必须6到12位，且不能出现空格'],
    });

});